/*
  读取流
*/
let fs = require('fs')
let data = ''

let reaerStream = fs.createReadStream('input.text')

reaerStream.setEncoding('UTF8')

reaerStream.on('data', (chunk) => {
  console.log('chunk:', chunk)
  data+=chunk
})

reaerStream.on('end', () => {
  console.log(data)
})

reaerStream.on('error', (err) => {
  console.log(err.stack)
})

console.log('读取完毕')

/*
  读取流
*/
let msg = '我是写入的内容，我是常德吴彦祖'
let writerStream = fs.createWriteStream('input.text')
writerStream.end()
writerStream.write(data + msg, 'UTF8')
writerStream.on('finish', () => {
  console.log('写入完毕！！！')
})
writerStream.on('error', (err) => {
  console.log(err.stack)
})
console.log('写入执行结束！！！')